package com.kws.merchant.service.impl;


import com.kws.common.config.constant.MinioCommonBucket;
import com.kws.merchant.domain.OperationPollingDevice;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.merchant.mapper.OperationPollingDeviceMapper;
import com.kws.merchant.service.OperationPollingDeviceService;
import com.kws.merchant.util.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;

/**
 * 运维-巡检设备关联表(OperationPollingDevice)表服务实现类
 *
 * @author yxy
 * @since 2024-10-28 11:32:39
 */
@Service("operationPollingDeviceService")
public class OperationPollingDeviceServiceImpl extends ServiceImpl<OperationPollingDeviceMapper, OperationPollingDevice> implements OperationPollingDeviceService {

    @Resource
    private OperationPollingDeviceMapper operationPollingDeviceMapper;

    @Value("${minio.ENDPOINT}")
    private String minioUrl;

    /**
     * 分页查询列表
     */
    @Override
    public Page<OperationPollingDevice> pageList(OperationPollingDevice operationPollingDevice) {
        Page<OperationPollingDevice> page = new Page<>(0, 10);
        LambdaQueryWrapper<OperationPollingDevice> queryWrapper = Wrappers.lambdaQuery();

        return this.page(page, queryWrapper);
    }

    /**
     * 根据巡检id删除巡检设备
     * @param pollingId
     * @return
     */
    @Override
    public boolean deleteByPollingId(Long pollingId) {
        return this.remove(Wrappers.<OperationPollingDevice>lambdaQuery().eq(OperationPollingDevice::getPollingId,pollingId));
    }

    /**
     * 根据巡检id查询巡检设备
     * @return
     * @param pollingId
     */
    @Override
    public List<OperationPollingDevice> listByPollingId(Long pollingId) {
        List<OperationPollingDevice> list=operationPollingDeviceMapper.listByPolling(pollingId);
        list.forEach(x->{
            if (x.getFile()!=null){
                x.setFile(FileUtil.fixFileName()+x.getFile());
            }
        });
        return list;
    }

    /**
     * 修改巡检记录
     * @param pollingDevices
     */
    @Override
    public void updatePollingDevice(List<OperationPollingDevice> pollingDevices) {
        pollingDevices.forEach(x->{
            x.setFile(FileUtil.subFileName(x.getFile()));
        });
        this.saveOrUpdateBatch(pollingDevices);
    }


}
